<template>
    <div>
      <h2>修改</h2>
      <table class="table table-bordered">
        <tbody>
          <tr>
            <td>名称</td>
            <td>
              <input type="text" v-model="form.name" />
            </td>
          </tr>
        
          <tr>
            <td>科室类别</td>
            <td>
              <select v-model="form.keshi">
                <option value="">请选择</option>
                <option>内科</option>
                <option>外科</option>
                <option>骨科</option>
                <option>儿童科</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>创建时间</td>
            <td>
              <input type="date" v-model="form.ketime" />
            </td>
          </tr>
          <tr>
            <td>人数</td>
            <td>
              <input type="text" v-model="form.renshu" />
            </td>
          </tr>
          <tr>
            <td>介绍</td>
            <td>
              <textarea v-model="form.introduce"> </textarea>
            </td>
          </tr>
          <tr>
            <td></td>
            <td>
              <button @click="Add">修改</button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </template>
  
  <script setup lang="ts">
  import axios from "axios";
  import { onMounted, reactive, ref } from "vue";
  import { useRoute, useRouter } from "vue-router";
  import "bootstrap/dist/css/bootstrap.min.css";
  const router = useRouter();
  const route=useRoute();
  const form: any = reactive({
    id: 0,
    name: "",
    pwd: "",
    keshi: "",
    ketime: "",
    renshu: "",
    introduce: "",
    isdelete: true,
  });
  const Add=()=>{
      if(!form.name){
          alert("名称不能为空");
          return;
      }
      if(form.name.length>=20){
          alert("名称不能超过二十个字符");
          return;
      }
  
      axios.put("https://localhost:7015/api/yiliaokeshi/Update",form).then(res=>{
          if(res.data>0){
              alert("修改成功");
              router.push("showkeshi")

          }
          else
          {
              alert("修改失败");
              console.log(res);
          }
      })
  }


const Fantian=()=>{
    axios.get("https://localhost:7015/api/yiliaokeshi/GetYiliaokeshi?id="+route.query.id).then(res=>{
        let b=res.data;
        form.id=b.id;
        form.name=b.name;
        form.pwd=b.pwd;
       
        form.keshi=b.keshi;
        form.ketime=b.ketime.substring(0,10);
        form.renshu=b.renshu;
        form.introduce=b.introduce;
        form.isdelete=b.isdelete;

    })
}

onMounted(()=>{
    Fantian();
})



  </script>
  
  <style scoped></style>
  